package com.huluspace.jpahibernate.security;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

public class CustomUserDetails implements UserDetails {
  private Long id;
  private String username;
  private String password;
  private Collection<? extends GrantedAuthority> authorities;

  public CustomUserDetails(Long id, String username, String password, Collection<? extends GrantedAuthority> authorities) {
    this.id = id;
    this.username = username;
    this.password = password; // 在JWT校验流程中可设为 ""
    this.authorities = authorities;
  }

  @Override public Collection<? extends GrantedAuthority> getAuthorities() { return authorities; }
  @Override public String getPassword() { return password; }
  @Override public String getUsername() { return username; }
  @Override public boolean isAccountNonExpired() { return true; }
  @Override public boolean isAccountNonLocked() { return true; }
  @Override public boolean isCredentialsNonExpired() { return true; }
  @Override public boolean isEnabled() { return true; }

  @Override
  public String toString() {
    return "CustomUserDetails{" +
        "id=" + id +
        ", username='" + username + '\'' +
        ", authorities=" + authorities.stream()
        .map(GrantedAuthority::getAuthority)
        .toList() +
        '}';
  }
}
